from pydantic import BaseModel, Field
from typing import List, Optional, Dict, Any
from datetime import datetime

class AIModelBase(BaseModel):
    name: str
    provider: str  # 如 OpenAI, Anthropic, Gemini 等
    model_id: str  # 如 gpt-4, claude-3-opus 等
    api_type: str  # 如 openai, anthropic, google 等
    description: Optional[str] = None
    max_tokens: int = 4096
    temperature_default: float = 0.7
    api_key: str
    api_endpoint: Optional[str] = None
    api_version: Optional[str] = None
    stream_enabled: bool = True  # 添加流式输出配置，默认启用
    is_active: bool = True
    
    model_config = {
        'protected_namespaces': ()
    }

class AIModelCreate(AIModelBase):
    pass

class AIModelUpdate(AIModelBase):
    pass

class AIModel(AIModelBase):
    id: str
    created_at: str
    updated_at: str
    
    model_config = {
        'from_attributes': True,
        'json_encoders': {
            datetime: lambda v: v.isoformat()
        }
    }

class AIModelResponse(AIModelBase):
    id: str
    created_at: str
    updated_at: str
    # 不返回 api_key 等敏感信息 

class AIModelTest(BaseModel):
    message: str

class AIModelTestResult(BaseModel):
    response: str 